<template>
  <div class="cart-bar">
    <span class="client-service">
      <i class="iconfont bee-kefu"></i>
      <span>客服</span>
    </span>
    <span class="cart" @click="$router.push('/cart')">
      <i class="iconfont bee-gouwuche1"></i>
      <span>购物车</span>
      <span class="count" v-show="count > 0">{{ count }}</span>
    </span>
    <div class="action-buttons">
      <div class="add-cart-button" @click="$emit('addCart')">加入购物车</div>
      <div class="buy-now-button" @click="$emit('buyNow')">立即购买</div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'CartBar',
  computed: {
    ...mapGetters({
      count: 'cart/countGetter'
    })
  },
  mounted() {
    this.getCartListApi()
  },
  methods: {
    ...mapActions({
      getCartListApi: 'cart/getCartListApi'
    })
  }
}
</script>

<style lang="less" scoped>
.cart-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 50px;
  padding: 0 15px;
  background-color: #fff;
  .client-service {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    .bee-kefu {
      font-size: 16px;
    }
  }
  .cart {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    .bee-cart {
      font-size: 14px;
    }
    .count {
      display: inline-block;
      text-align: center;
      position: absolute;
      right: -4px;
      top: -4px;
      padding: 0 3px;
      border-radius: 15px;
      background-color: #ee0a24;
      color: #fff;
      font-size: 10px;
    }
  }
  .action-buttons {
    display: flex;
    width: 260px;
    font-size: 14px;
    color: #fff;
    .add-cart-button {
      text-align: center;
      width: 50%;
      height: 35px;
      line-height: 35px;
      border-top-left-radius: 15px;
      border-bottom-left-radius: 15px;
      background: linear-gradient(90deg, #6bd8d8, #1baeae);
    }
    .buy-now-button {
      text-align: center;
      width: 50%;
      height: 35px;
      line-height: 35px;
      border-top-right-radius: 15px;
      border-bottom-right-radius: 15px;
      background: linear-gradient(90deg, #0dc3c3, #098888);
    }
  }
}
</style>
